package cn.yogehaoren;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author WangNing
 * @since 1.0
 */
public class TestAMQP {

    public static void main(String[] args) {

        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(RabbitConfig.class);
        RabbitAdmin rabbitAdmin = applicationContext.getBean(RabbitAdmin.class);
        RabbitTemplate rabbitTemplate = applicationContext.getBean(RabbitTemplate.class);

        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setHeader("aa", "bb");
        Message message = new Message("Hello Spring-boot-AMQP".getBytes(), messageProperties);
        rabbitTemplate.convertAndSend("exchange-2","springboot.lalala", message, new MessagePostProcessor() {
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setHeader("cc", "ee");
                return message;
            }
        });



    }

}
